'''###########################################################################################################################
### File: rayman-panda3d.py
### Name: Patrick Delaney, Andrew Oberlin
### Class: CSE 487
### Instructor: Dr.Zmuda
### Assignment: Final Project
### Description: Class for handling the character generation
################ 
'''

from menu_button import MenuButton
from menu_scroller import MenuScroller
from panda3d.core import Vec2, Point3, Vec3, Vec4
from direct.gui.DirectGui import *
from objects import Object
from create_object import ObjectGenerator

class ObjectGen:

	'''
	### Name: __init__ (Constructor)
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: 
	'''
	def __init__(self, parent, projectDirectory,gameMaker):
		self.parent = parent
		self.models = dict()
		self.projectDirectory = projectDirectory
		self.gameMaker = gameMaker
		self.__loadModels()
	
	'''
	### Name: __loadModels
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: Loads the GUI objects
	'''
	def __loadModels(self):
		self.models['background'] = self.parent.loader.loadModelCopy("models/plane")
		self.backgroundTexture = self.parent.loader.loadTexture("models/gui/game_maker/menu_background.jpg")
		self.models['background'].setTexture(self.backgroundTexture)
		self.models['background'].setTransparency(1)
		self.models['background'].setScale(2.67, 1, 2)
		self.models['background'].reparentTo(self.parent.base.aspect2d)
		
		## CHANGE THE LOGO HERE
		self.models['logo'] = self.parent.loader.loadModelCopy("models/plane")
		self.logoTexture = self.parent.loader.loadTexture("models/gui/game_maker/object_generator_logo.png")
		self.models['logo'].setTexture(self.logoTexture)
		self.models['logo'].setTransparency(1)
		self.models['logo'].setScale(2.67, 1, 0.35)
		self.models['logo'].setPos(0, 0, 0.75)
		self.models['logo'].reparentTo(self.parent.base.aspect2d)
		
		self.models['new_obj_button'] = MenuButton(
			self.parent, 'new_obj_button', 'models/gui/game_maker/dialog_button', 
			self.addObj, Vec3(0, 0, 0.35), isMovie = False, text="New Object", 
			textPos=Vec3(-0.275, 0, -0.025), scale=Vec3(0.6,1,0.2)
		)
		
		numItemsVisible = 4
		itemHeight = 0.11
		
		path = "projects/" + self.projectDirectory + "/objects"  #Need to find a way to get ProjectOne name to make this universal
		self.models['existing_obj_scroller'] = MenuScroller(
		    self.parent, 'main_obj_scroller', path, '.item', (0.0, 0.7, -0.05, 0.59), (-0.35, 0, -0.5),
			numItemsVisible,itemHeight, (-0.2, 0.2, -0.37, 0.11), (0.35, 0, 0.4), self.onClick
		)
		
		self.models['back_button'] = MenuButton(self.parent, 'create_object_button', 'models/gui/game_maker/back_button', 
			self.goBack, Vec3(-.90, 0, -.80),scale=0.25, textPos=Vec3(-0.20, 0, .15), isMovie = False, text="Go Back")
	
	'''
	### Name: hide
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: hides this GUI
	'''
	def hide(self):
		for key in self.models.keys():
			self.models[key].hide()
			
	'''
	### Name: show
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: show this GUI
	'''
	def show(self):
		for key in self.models.keys():
			self.models[key].show()
			
		self.models['existing_obj_scroller'].removeNode()
		path = "projects/" + self.projectDirectory + "/objects"
		numItemsVisible = 4
		itemHeight = 0.11
		
		self.models['existing_obj_scroller'] = MenuScroller(
		    self.parent, 'existing_obj_scroller', path, '.item', (0.0, 0.7, -0.05, 0.59), (-0.35, 0, -0.5),
			numItemsVisible,itemHeight, (-0.2, 0.2, -0.37, 0.11), (0.35, 0, 0.4), self.onClick
		)
	
	
	def addObj(self):
		self.object = Object()
		self.objectGenerator = ObjectGenerator(self.parent, self.projectDirectory, self, self.object)
		self.hide()
		
	def onClick(self, item, dir):
		self.object = Object()
		self.object.load(dir + "/" + item)
		self.objectGenerator = ObjectGenerator(self.parent, self.projectDirectory, self, self.object)
		self.hide()
		
	'''
	### Name: goBack
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: goes back to the previous GUI
	'''
	def goBack(self):
		self.hide()
		self.gameMaker.models['background'].show()
		self.gameMaker.models['logo'].show()
		self.gameMaker.models['create_character_button'].show()
		self.gameMaker.models['create_object_button'].show()
		self.gameMaker.models['create_level_button'].show()
		self.gameMaker.models['back_button'].show()
		
	
		